﻿CREATE PROCEDURE [dbo].[proc_Customer_SearchMnemonicWorks]
	(
		@MnemonicWorks nvarchar(50),
		@UserName nvarchar(50)
	)
AS
Begin
	DECLARE @CompanyId int,@cSql nvarchar(3000)
	Select @CompanyId=CompanyId From Employee Where UserName=@UserName

	Set @cSql = ';WITH List As(Select top 6 Id,
		CustomerId,CustomerName,MnemonicWorks,'''' As Tel,
		(Select Top 1 EName From Employee Where UserName=Customer.CreateName) As CreateNameEName,
		Convert(varchar(2),ProtectId) As Protect,CreateDate 
		From Customer
		Where CompanyId='+Convert(varchar(10),@CompanyId)+' And
		((CustomerName Like ''%'+@MnemonicWorks+'%'' And  
		'''+@MnemonicWorks+'''<>'''') Or
		MnemonicWorks='''+@MnemonicWorks+''')
	)

	Select * From List Where CustomerName Not Like ''%-zd-%'''

	Exec(@cSql)
End
